// let matrix = new Array(5).fill(0).map(() => Array(4).fill(1));
// 行
let matrix = [
  [2, 3, 1],
  [2, 5, 3],
  [4, 2, 1],
];
let m = matrix.length;
let n = matrix[0].length;
// for (let i = 0; i < m; i++)
//   for (let j = 0; j < n; j++) {
//     matrix[i][j] = i + j;
//   }
let dp = new Array(3).fill(0).map(() => new Array(3).fill(0));
dp[0][0] = matrix[0][0];
for (let i = 1; i < m; i++) {
  dp[i][0] = matrix[i][0] + dp[i - 1][0];
}
for (let j = 1; j < n; j++) {
  dp[0][j] = matrix[0][j] + dp[0][j - 1];
}
// console.log(matrix);
console.log(dp);

for (let i = 1; i < m; i++)
  for (let j = 1; j < n; j++) {
    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + matrix[i][j];
  }

console.log(dp[m - 1][n - 1]);
